﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using VersionComparer.Base;
using VersionComparer.DataModel.Assemblies.Images;

namespace VersionComparer.DataModel.Assemblies
{
    [Serializable]
    [Order(6)]
    public class EventItem : AssemblyItemBase <EventInfo>
    {

        protected override System.Type AssociatedType(System.Reflection.EventInfo value)
        {
            return value.EventHandlerType;
        }

        protected override void Initialize(EventInfo value)
        {
            base.Initialize(value);
            Name = value.Name;
            MethodInfo addMethod = value.GetAddMethod();
            IsPublic = addMethod.IsPublic;
            IsFamily = addMethod.IsFamily;
            IsFamilyOrAssembly = addMethod.IsFamilyOrAssembly;
            IsStatic = addMethod.IsStatic;
            Text = string.Format("{0} event {1} {2};", AccessorsAsCode, UnderlyingTypeName, Name);
        }


        protected override CustomAttributeData[] GetAttributes(EventInfo value)
        {
            return CustomAttributeData.GetCustomAttributes(value).ToArray();
        }
        protected override string GetFullText(EventInfo value)
        {
            RtfBuilder builder = new RtfBuilder();
            BuildRtf(builder, false, false);
            
            return builder.Text;
        }

        protected override void BuildRtf(RtfBuilder builder, bool differencesOnly, bool useParentColor)
        {
            BuildAttributesRtf(builder, differencesOnly, useParentColor);
            builder.Append(AccessorsAsCode, keywordColor);
            builder.Append("event ", keywordColor);
            builder.Append(UnderlyingTypeRtf);
            builder.AppendLine(string.Format(" {0};" , Name));

        }

        protected override System.Drawing.Image GetSpecificImage()
        {
            return AssemblyResources._event;
        }
    }
}
